<template>
    <div class="">
        <el-dialog
                :title="title"
                :visible.sync="dialogFormVisible"
                width="1000px"
                :close-on-click-modal=false
                @close="close"
        >
            <el-form ref="form" :model="form" label-width="100px">
                <el-form-item label="排序" prop="sort">
                    <el-input v-model.trim="form.sort" autocomplete="off" type="number" placeholder="请输入排序"></el-input>
                </el-form-item>
                <el-form-item label="公告类型" prop="noticeType" v-show="this.title=='添加'" :required="true">
                    <el-radio v-model="form.noticeType" label="1">前台公告</el-radio>
                    <el-radio v-model="form.noticeType" label="2" v-show="!form.storeId">后台公告</el-radio>
                </el-form-item>
                <el-form-item label="公告标题" prop="title" :required="true">
                    <el-input v-model.trim="form.title" autocomplete="off" placeholder="请输入公告标题"></el-input>
                </el-form-item>
                <el-form-item label="公告简介" prop="title" v-if="form.noticeType=='2'">
                    <el-input v-model.trim="form.introduction" autocomplete="off" type="textarea"
                              placeholder="请输入公告简介"></el-input>
                </el-form-item>
                <el-form-item label="公告详情" prop="body">
<!--                    <vab-quill v-model="form.body" :min-height="400"></vab-quill>-->
                    <baidu-ueditor :content='form.body' @ueditor='getUeditor'></baidu-ueditor>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button size="medium" @click="close">取 消</el-button>
                <el-button size="medium" type="primary" @click="save">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
    import vabQuill from "@/plugins/vabQuill";
    import baiduUeditor from "@/plugins/baidu-ueditor";
    import {noticeSave} from "@/api/setup";

    export default {
        components: {vabQuill,baiduUeditor},
        name: "goodlistedit",
        created() {
        },
        data() {
            return {
                form: {
                    id: '',
                    sort: "1",
                    title: "",
                    body: "",
                    noticeType: "1",
                    introduction: "",
                },
                title: "",
                dialogFormVisible: false,
            }
        },
        methods: {
            showEdit(row) {
                if (!row) {
                    this.title = "添加";
                } else {
                    this.title = "编辑";
                    this.form = Object.assign({}, row);
                }
                this.dialogFormVisible = true;
            },
            // setStoreId(storeId){
            //     this.form.storeId = storeId
            // },
            onSearch() {
                this.fetchData();
            },
            close() {
                this.$refs["form"].resetFields();
                this.form = this.$options.data().form;
                this.dialogFormVisible = false;
            },
            getUeditor(content) {
                this.form.body = content
            },
            save() {
                this.$refs["form"].validate(async (valid) => {
                    if (valid) {
                        const {msg} = await noticeSave(this.form);
                        this.$baseMessage(msg, "success");
                        this.$emit("fetchData");
                        this.close();
                    } else {
                        return false;
                    }
                });
            },
        }
    };
</script>
<style lang="scss" scoped>
    .edui-editor {
        width: 826px !important;
    }
</style>
